import {List} from "antd-mobile";
import React, {useEffect, useState} from "react";
import {useLocation, useNavigate} from "react-router-dom";
import {airConditionInfo, batteryInfo, DashboardData} from "../../../Datasource";
import {
    Form,
    Input,
    Button,

} from 'antd-mobile'

const DeviceEdit = () => {
    const location = useLocation()
    const navigate = useNavigate()
    const [initialValues, setInitialValues] = useState<any>({})
    const temp = location.pathname.split('/')
    const typeId = Number(temp[temp.length - 2])

    useEffect(() => {
        if (location) {

            const deviceId = Number(temp[temp.length - 1])
            if (typeId === 1) {
                airConditionInfo.map(e => {
                    if (e.id === deviceId) {
                        setInitialValues(e)
                    }
                })
            } else if (typeId === 0) {
                batteryInfo.map(e => {
                    if (e.id === deviceId) {
                        setInitialValues(e)
                    }
                })
            }
        }
    }, [])

    if (initialValues.name) {
        return <Form initialValues={initialValues}
                     layout='horizontal' mode='card'
                     footer={
                         <Button block type='submit' color='primary' size='large' onClick={() => {
                             navigate('/')
                         }}>
                             提交
                         </Button>
                     }
        >
            <Form.Item name='name' label='设备名称'>
                <Input placeholder='请输入'/>
            </Form.Item>
            <Form.Item name='machineRoom' label='机房名称'>
                <Input placeholder='请输入'/>
            </Form.Item>
            <Form.Item name='district' label='所属区县'>
                <Input placeholder='请输入'/>
            </Form.Item>
            <Form.Item name='type' label='设备类型'>
                <Input placeholder='请输入'/>
            </Form.Item>
            {typeId === 1 &&
                <Form.Item name='supplyMode' label='送风方式'>
                    <Input placeholder='请输入'/>
                </Form.Item>}
            <Form.Item name='supplyMode' label='送风方式'>
                <Input placeholder='请输入'/>
            </Form.Item>
            <Form.Item name='capacity' label='额定容量'>
                <Input placeholder='请输入'/>
            </Form.Item>
            <Form.Item name='productionTime' label='出厂日期'>
                <Input placeholder='请输入'/>
            </Form.Item>
            <Form.Item name='updatePerson' label='修改人'>
                <Input placeholder='请输入'/>
            </Form.Item>
            <Form.Item name='updateTime' label='修改时间'>
                <Input placeholder='请输入'/>
            </Form.Item>
        </Form>
    } else {
        return null
    }
}

export default DeviceEdit
